package tuiLayer;
import controlLayer.PersonCtrl;
import java.util.Scanner;

public class PersonUI
{
    private PersonCtrl personController;
    public PersonUI()
    {
        personController = new PersonCtrl();
    }
    
    public void personUIMenu()
    {        
       boolean exit = false;
       while(!exit)//that is: while exit is false
       {
           String choise = subMenus();
           switch(choise)
           {
               case "1":
               createPerson();
               break;
               case "2": 
               updatePerson();
               break;
               case "3": 
               deletePerson();
               break;
               case "4": 
               findPerson();
               break;
               case "5": 
               exit = true;
               break;
               default:
               break;
           }
       }
    }
    
    public boolean createPerson()
    {
       System.out.print('\u000C');
       System.out.println("*** Creating New Person ***");
       Scanner keyboard = new Scanner(System.in);
       System.out.println("Please enter name:");
       String name = keyboard.next();
       System.out.println("Please enter address:");
       String address = keyboard.next();
       System.out.println("Please enter postal code:");
       String postalCode = keyboard.next();
       System.out.println("Please enter city:");
       String city = keyboard.next();
       System.out.println("Please enter phone number:");
       String phone = keyboard.next();
       
       return personController.createPerson(name, address, postalCode, city, phone);
    }
    
    public void findPerson()
    {
       System.out.print('\u000C');
       Scanner keyboard = new Scanner(System.in);
       System.out.println("Enter name or phone number: ");
       String searchTerm = keyboard.next();
       
       personController.findPerson(searchTerm);
    }
    
    public void updatePerson()
    {
       System.out.print('\u000C');
       Scanner keyboard = new Scanner(System.in);
       System.out.println("Enter phone number: ");
       String searchTerm = keyboard.next();
       
       personController.updatePerson(searchTerm);  
    }
    
    public void deletePerson()
    {
       System.out.print('\u000C');
       Scanner keyboard = new Scanner(System.in);
       System.out.println("enter phone number: ");
       String searchTerm = keyboard.next();
       personController.deletePerson(searchTerm);
       
    }
    
    public String subMenus()
    {      // makes an object keyboard to read input from the screen
       Scanner keyboard = new Scanner(System.in);
       System.out.println("*** Person Menu ***");
       System.out.println(" (1) Create Person");
       System.out.println(" (2) Update Person");
       System.out.println(" (3) Delete Person");
       System.out.println(" (4) Find Person");
       System.out.println(" (5) Back");
       System.out.print("\n Choose: ");
            
       String choise = keyboard.next();
       return choise;
    }
}
